//
//  XMGSubTagCell.m
//  BuDeJie
//
//  Created by xiaomage on 16/3/15.
//  Copyright © 2016年 小码哥. All rights reserved.
//

#import "XMGSubTagCell.h"

#import <UIImageView+WebCache.h>
#import "RWSubTagItem.h"

@interface XMGSubTagCell ()

@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *nameView;
@property (weak, nonatomic) IBOutlet UILabel *numView;


@end

@implementation XMGSubTagCell

// 调用系统的setFrame
- (void)setFrame:(CGRect)frame {

    RWLog(@"%@", NSStringFromCGRect(frame));
    frame.size.height -= 1;
    // 才是真正的赋值
    [super setFrame: frame];
}

/*
 头像变成圆角 1.设置头像圆角 2.裁剪图片
 处理数字
 */

- (void)setItem:(RWSubTagItem *)item {
    
    _item = item;
    
    // 设置内容
    _nameView.text = item.theme_name;
    
    [self resolveNum];
    
    [_iconView sd_setImageWithURL:[NSURL URLWithString:item.image_list] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"]];
    
}
- (void)awakeFromNib {
    // Initialization code
    _iconView.layer.cornerRadius = 30;
    _iconView.layer.masksToBounds = YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

// 处理订阅的数字
- (void)resolveNum {

    NSString *numStr = [NSString stringWithFormat:@"%@人订阅", _item.sub_number];
    NSInteger num = _item.sub_number.integerValue;
    if (num > 10000) {
        CGFloat numF = num /10000.0;
        numStr = [NSString stringWithFormat:@"%.1f万人订阅", numF];
        numStr = [numStr stringByReplacingOccurrencesOfString:@".0" withString:@""];
    }
    _numView.text = numStr;
}

@end
